﻿@using Webdiyer.WebControls.Mvc
@model List<Web.Models.TimeChartModel>
@{
    ViewBag.Title = "耗时性能图";
    Layout = "~/Views/Shared/_Layout.cshtml";
    Dictionary<int, Dyd.BaseService.Monitor.Domain.PlatformManage.Model.timewatchConnModel> dic =
        ViewBag.TimeWatchConn as Dictionary<int, Dyd.BaseService.Monitor.Domain.PlatformManage.Model.timewatchConnModel>;
}
<div class="head">
    <div class="title">
        耗时性能图
    </div>
</div>
<div class="orderlist m10 myorder">
    @using (Html.BeginForm("Chart", "TimeWatchLog", FormMethod.Get, new RouteValueDictionary { { "id", "searchForm" } }))
    {
        <div class="item_list pt10">
            <div class="item_list">
                <ul>
                <li>
                    <label>SQLHash/Api</label>
                    <input type="text" class="text" id="logtag" name="logtag" value="@ViewBag.logtag" />
                </li>
                <li>
                    <label>查询类型</label>
                    <select id="type" name="type">
                         @foreach (var o in Dyd.BaseService.Monitor.Core.EnumUtils<XXF.BaseService.Monitor.SystemRuntime.EnumTimeWatchLogType>.GetAllEnumsOfList2())
                         {
                             if (o.Value != "1")
                             { 
                               <option value="@o.Value" @Html.Raw((int)ViewBag.type+"" == o.Value+"" ? "selected=selected" : "")>@o.Text</option>
                             }
                         }
                    </select>
                </li>
                <li>
                    <label>数据库</label>
                    <select name="connid" id="connid">
                        @foreach (KeyValuePair<int, Dyd.BaseService.Monitor.Domain.PlatformManage.Model.timewatchConnModel> d in dic)
                        { 
                            <option value="@d.Key"@Html.Raw(d.Key == ViewBag.Connid ? "selected=selected" : "") >@d.Value.name</option>
                        }
                    </select>
                </li>
                    <li>
                        <label>时间</label><input type="text" class="text" name="date" value="@ViewBag.date" />(支持日[2015-04-01],月[2015-04],年[2015])
                    </li>
                    <li>
                        <label>耗时类型</label>
                        <select name="datatype">
                            <option value="avg" @(ViewBag.datatype + "" == "avg" ? "selected='selected'" : "")>平均耗时</option>
                            <option value="max" @(ViewBag.datatype + "" == "max" ? "selected='selected'" : "")>最大耗时</option>
                            <option value="min" @(ViewBag.datatype + "" == "min" ? "selected='selected'" : "")>最小耗时</option>
                            <option value="count" @(ViewBag.datatype + "" == "count" ? "selected='selected'" : "")>调用次数</option>
                        </select>
                    </li>
                    <li class="search">
                        <input type="submit" class="btn1" value="搜索" onclick="return search();" accesskey="S" /></li>
                </ul>
            </div>
        </div>
    }
</div>
<script type="text/javascript" src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
    <script src="~/Content/js/chart.js"></script>
<div>
     @foreach (var m in Model)
     {
        <div id="container@(m.Key)" style="width:90%;height:400px; float:left"></div>
     }
</div>
<script>

    $("[type='checkbox']").each(function (i) {
        //alert($(this).val());
        if ($('#columns').val().indexOf($(this).val()) > -1 && $(this).val() != '') {
            $(this).attr("checked", true);
        }
    });
    function chooseAll(item) {
        //alert($(item).attr("checked"));
        if ($(item).attr("checked")) {
            $("[type='checkbox']").attr("checked", true);
        }
        else
            $("[type='checkbox']").attr("checked", false);
    }
    function search() {
        if ($("#logtag").val() == '')
        { alert("SQLHash/Api不能为空"); return false; }
        var choosed = '';
        $("[type='checkbox']").each(function (i) {
            if ($(this).attr("checked") && $(this).val() != '') {
                choosed += $(this).val() + ',';
            }
        });
        $("#columns").val(choosed);
        return true;
    }
    $(function () {
          @foreach (var m in Model)
          {
              //",m.Key,m.Title,m.SubTitle,m.DataJson,m.YTitle,m.UnitText, m.StartDate.ToString("yyyy,MM,dd"),m.StartDate.Date.AddDays(1).ToString("yyyy,MM,dd")))
              var c = @"$('#container'+'{key}').highcharts({
            chart: {
                zoomType: 'x',
                spacingRight: 20
            },
            title: {
                text: '{title}'
            },
            subtitle: {
                text: document.ontouchstart === undefined ?
                    '{subtitle}' :
                    'Pinch the chart to zoom in'
            },
            xAxis: {
                type: 'datetime',
                maxZoom: {maxzoom}, // fourteen days
                //tickInterval:60*60*1000,
                max:Date.UTC({enddate}),
                dateTimeLabelFormats:{day: '%b月%e日',month: '%y年%b月' ,year: '%Y'},
                title: {
                    text: null
                }
            },
            yAxis: {
                title: {
                    text: '{ytitle}'
                }
            },
            tooltip: {
                shared: true
            },
            legend: {
                enabled: false
            },
            plotOptions: plotOptions1,

            series: [{
                type: 'area',
                name: '{unittext}',
                pointInterval:  {pointinterval},
                pointStart: Date.UTC({startdate}),
                data: {datajson}
            }]
        });".Replace("{key}", m.Key).Replace("{title}", m.Title).Replace("{subtitle}", m.SubTitle)
                  .Replace("{datajson}", m.DataJson).Replace("{ytitle}", m.YTitle)
                  .Replace("{startdate}", m.StartDate.ToString("yyyy,MM,dd"))
                  .Replace("{unittext}", m.UnitText)
                  .Replace("{maxzoom}", m.MaxZoom)
                  .Replace("{pointinterval}", m.PointInterval)
                  .Replace("{enddate}", m.EndDate.ToString("yyyy,MM,dd"));
        @Html.Raw(c)
          }
      });

</script>